package com.cn.mtm2000.mtmgeneratorsqlutil.mtmgeneratorsqlutil.generatorutil.config;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;


public class MysqlDao implements DatabaseDao {

	public List<Property> queryProperties(Connection conn, String tableName, String databaseName) throws SQLException {
		tableName=tableName.toLowerCase();
		String sql = "SELECT COLUMN_NAME columnName, DATA_TYPE dataType, NUMERIC_PRECISION numericPrecision,NUMERIC_SCALE numericScale,COLUMN_KEY columnKey,EXTRA extra " + "FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = ? AND TABLE_SCHEMA='" + databaseName + "' ORDER BY ORDINAL_POSITION ASC ";
		QueryRunner qr = new QueryRunner();
		List<Property> list = (List<Property>) qr.query(conn, sql, new BeanListHandler(Property.class), new String[] { tableName });
		return list;
	}

}
